/*
 * Neighbouring Numbers with the smallest distance to each other.
 *
 * @version  1.0 27 Jan 2013
 * @author Myhaylo Kotsyuruba (javatrainee15)
 */

import java.util.ArrayList;
import java.util.Scanner;

public class NeighbouringNumbers {
    public static void main(String[] args) {
        ArrayList<Integer> numbers = getNubers();
        int index = getIndexSmallestDistance(numbers);
        showResult(index);
    }
    
    static ArrayList<Integer> getNubers() {
        System.out.print("Enter the sequence: ");
        
        Scanner inputFromKeybord = new Scanner(System.in);
        String inputString = inputFromKeybord.nextLine();
        String[] numberString = inputString.split(" ");
        
        ArrayList<Integer> numbers = new ArrayList<Integer>();
        for (String elementString : numberString) {
            numbers.add(Integer.parseInt(elementString));
        }
                
        return numbers;
    }
    
    static int getIndexSmallestDistance(ArrayList<Integer> numbers) {
        if (numbers.size() < 3) {
            return 0;
        }
        int indexSmallestDistance = 0;
        int smallestDistance = Math.abs(numbers.get(0) - numbers.get(1));
        for (int index = 1; index < (numbers.size() - 1); index++) {
            int distanse = Math.abs(numbers.get(index) - numbers.get(index + 1));
            if (distanse < smallestDistance) {
                smallestDistance = distanse;
                indexSmallestDistance = index;
            }
        }
        return indexSmallestDistance;
    }
    
    static void showResult(int number) {
        System.out.println("Answer: " + number);
    }
}